package com.itheima.mylistdemo;

import java.util.LinkedList;

/*
    需求：手写一个栈容器

 */
public class Test {
    public static void main(String[] args) {
        MyStack stack=new MyStack();
        stack.push("hello");
        stack.push("world");
        stack.push("java");

        //取出
        System.out.println(stack.pop());
        System.out.println(stack.pop());
        System.out.println(stack.pop());

    }

}

//栈特点：先进后出
class MyStack{
    private LinkedList<Object> stack=new LinkedList<>();

    //存元素方法
    public void push(Object obj){
        stack.addFirst(obj);

    }

    //取元素方法
    public Object pop(){
        return stack.removeFirst();
    }


}